<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-stock__pregnancy}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-select v-model="dataForm.houseId" placeholder="猪舍" clearable>
            <el-option
                v-for="item in houses"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
          <!--<pig-tree :props="props"
            :options="optionData"
            :value="valueId"
            :filter="0"
            :clearable="isClearable"
            :accordion="isAccordion"
            @getValue="getValue($event)"></pig-tree>-->
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="addHandle()" type="success">{{ $t('add') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle" style="width: 100%;">
        <el-table-column prop="houseName" label="猪舍" sortable="custom" header-align="center" align="center"></el-table-column>
        <el-table-column prop="sow" label="耳号" sortable="custom" header-align="center" align="center"></el-table-column>
        <el-table-column prop="checkDate" label="孕检日期" sortable="custom" header-align="center" align="center"></el-table-column>
        <el-table-column prop="status" label="孕检结果" sortable="custom" header-align="center" align="center">
          <template slot-scope="scope">
            {{ $getDictLabel("preg_status", scope.row.status) }}
          </template>
        </el-table-column>
        <el-table-column prop="operator" label="孕检员" sortable="custom" header-align="center" align="center"></el-table-column>
        <el-table-column prop="remark" label="备注" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createDate" label="创建时间" sortable="custom" header-align="center" align="center"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="170">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('basic:house:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <!--<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>-->
      <preg-check v-if="checkVisible" ref="refPregCheck" @refreshData="refreshData"></preg-check>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import SearchBar from './search-bar'
import PregCheck from '../stock/production/preg-check'
import PigTree from '../components/pig-tree'
/* eslint-disable */
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/history/pregnancy/page',
        getDataListIsPage: true,
        exportURL: '/history/pregnancy/export',
        deleteURL: '/history/pregnancy',
        deleteIsBatch: true
      },
      m_ltFields: [ { prop: 'houseName', label: '所在猪舍', fixed: 'left', readonly: true, search: true }, { prop: 'sow', label: '母猪耳号', fixed: 'left', required: true, search: true }, { prop: 'checkDate', label: '孕检日期', required: true, search: true }, { prop: 'status', label: '孕检结果', required: true, search: true }, { prop: 'operator', label: '孕检员' }, { prop: 'remark', label: '备注' }, { prop: 'createDate', label: '创建时间', readonly: true } ],
      searchFields: [ { prop: 'houseId', label: '所在猪舍', fixed: 'left', readonly: true, search: true }, { prop: 'sow', label: '母猪耳号', fixed: 'left', required: true, search: true }, { prop: 'checkDate', label: '孕检日期', required: true, search: true }, { prop: 'checkDateStart', label: '孕检日期', required: false, search: false }, { prop: 'checkDateEnd', label: '孕检日期', required: false, search: false }, { prop: 'status', label: '孕检结果', required: true, search: true }],
      dataForm: {
        id: ''
      },
      checkVisible: false
    }
  },
  components: {
    SearchBar,
    PregCheck,
    PigTree
  },
  methods: {
    addHandle (id) {
      this.checkVisible = true
      this.$nextTick(() => {
        this.$refs.refPregCheck.dataForm.id = id
        this.$refs.refPregCheck.init()
      })
    },
    showUpload () {
      this.uploadVisible = true
      this.$nextTick(() => {
        this.$refs.upload.init()
      })
    }
  }
}
</script>
